home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-02 | 11.6 KB | 503 lines | [TEXT/KAHL] |
- * ***
- * Methods for an object inspector
- *
- * Julian Barkway (c) October 1994. All rights reserved.
- *
- * v3.1.3 - Initial release.
- * v3.1.5 - Inspectors completely re-designed to reflect improvements in the basic protocol
- * for Pane and SelectListPane. Protocol for ListPane absorbed into SelectListPane.
- *
- * ***
- Class InspectorView Object listPane editPane nameList theObject
- Class ObjectInspector InspectorView
- Class ClassHierarchyInspector InspectorView selectedClass
- Class CollectionInspector InspectorView
- Class ArrayInspector CollectionInspector
-
- Class InspectorListPane SelectListPane
- Class ObjectInspectorListPane InspectorListPane
- Class CollInspectorListPane InspectorListPane
- Class ArrayInspectorListPane CollInspectorListPane
-
- Class InspectorEditPane TextPane
- Class ObjectInspectorEditPane InspectorEditPane
- Class CHInspectorEditPane InspectorEditPane
- Class CollInspectorEditPane InspectorEditPane
-
- Methods Object 'inspecting'
- inspect
- ObjectInspector new; openOn: self
- ]
-
- Methods Class 'inspecting'
- inspect
- ClassHierarchyInspector new; openOn: self
- ]
-
- Methods Array 'modifying'
- removeValues: aConditionBlock
- | list |
- list <- List new.
- self do: [ :x |
- (aConditionBlock value: x ) ifFalse: [
- list addLast: x
- ]
- ].
- self become: (list asArray)
- ]
-
- Methods Class 'modifying'
- addInstanceVariable: aSymbol
- | s |
- variables isNil ifTrue: [
- variables <- Array new: 0
- ].
- s <- variables select: [ :i | aSymbol = i ].
- (s size > 0) ifTrue: [
- ^ true
- ]
- ifFalse: [
- variables <- variables grow: aSymbol.
- ^ false
- ]
- |
- removeInstanceVariable: aSymbol
- | s |
- s <- variables select: [ :i | aSymbol = i ].
- (s size = 0) ifTrue: [
- ^ true
- ]
- ifFalse: [
- j <- (variables size - 1).
- (j = 0) ifTrue: [
- variables <- nil
- ]
- ifFalse: [
- variables removeValues: [ :x | aSymbol = x ]
- ].
- ^ false
- ]
- ]
-
- Methods IndexedCollection 'inspecting'
- inspect
- CollectionInspector new; openOn: self
- ]
-
- Methods Array 'inspecting'
- inspect
- ArrayInspector new; openOn: self
- ]
-
- Methods InspectorListPane
- selectItem: aPoint
- self withSelectedItemSend: #showValue: to: (parent editPane)
- |
- createPopUpMenu
- ^ nil
- |
- editSelection: aSelector
- self withSelectedItemSend: aSelector to: (parent editPane)
- |
- clearEditPane: dummy
- (parent editPane) cancel
- ]
-
- Methods InspectorEditPane
- createPopUpMenu
- " Overridden by sub-classes "
- ^ nil
- |
- showValue: aValue
- " Overridden by sub-classes "
- ^ nil
- |
- changeValue
- (parent listPane) editSelection: #changeValue:
- |
- addValue
- (parent listPane) editSelection: #addValue:
- |
- removeValue
- (parent listPane) editSelection: #removeValue:
- |
- changeValue: aValue
- " Overridden by sub-classes "
- ^ nil
- |
- addValue: aValue
- " Overridden by sub-classes "
- ^ nil
- |
- removeValue: aValue
- " Overridden by sub-classes "
- ^ nil
- |
- cancel
- self clearAllText.
- pMenu disableItem: 1; disableItem: 2
- ]
-
- Methods InspectorView 'all'
- openOn: anObject
- theObject <- anObject.
- self createPanes.
- self initialisePanesIn: (self makeWindow: (self makeTitle)).
- self refreshListPane: theObject.
- |
- makeWindow: aTitle
- | maxW maxH posX posY centreScreen origin |
- maxW <- (smalltalk getMaxScreenArea) right.
- maxH <- (smalltalk getMaxScreenArea) bottom.
- centreScreen <- (0@0).
- origin <- (0@0).
- centreScreen x: ((maxW / 2) truncated).
- centreScreen y: ((maxH / 2) truncated).
- origin <- centreScreen - (170@200).
- maxW <- 340 min: ((origin x) + (maxW - 70)).
- maxH <- 200 min: ((origin y) + (maxH - 70)).
- ^ Window new;
- title: aTitle;
- openAt: origin withSize: (maxW@maxH).
- |
- createPanes
- " Overridden by sub-classes "
- ^ nil
- |
- listPane
- ^ listPane
- |
- editPane
- ^ editPane
- |
- initialisePanesIn: aWindow
- | ww wh ph pw |
- ww <- (aWindow size) x.
- wh <- (aWindow size) y.
- pw <- (ww / 2) truncated.
- listPane openOn: (self createListFrom: theObject)
- in: aWindow
- withSizeFrom: (-1 @ -1) to: (pw @ (wh + 1)).
- listPane font: 'geneva'; fontSize: 9; typeFace: 2;
- parent: self;
- button1Action: #clearEditPane:;
- button1DoubleClick: #selectItem:.
- editPane boundsFrom: ((pw - 1) @ -1) to: ((ww + 1) @ (wh + 1));
- attachTo: aWindow withSizing: (1 @ 1);
- font: 'monaco'; fontSize: 9;
- parent: self.
- listPane owner: listPane.
- editPane owner: editPane.
- self overrideDefaultPaneSettings.
- |
- overrideDefaultPaneSettings
- " Overridden by sub-classes "
- ^ nil
- |
- createListFrom: theInspectedObject
- " Overridden by sub-classes "
- ^ nil
- |
- refreshListPane: theInspectedObject
- listPane collection: (self createListFrom: theInspectedObject); setText
- |
- makeTitle
- " Overridden by sub-classes "
- ^ nil
- |
- theObject
- ^ theObject
- ]
-
- Methods ObjectInspectorListPane
- createPopUpMenu
- pMenu <- PopUpMenu new; owner: self; create.
- pMenu addItem: 'Inspect' action: #inspectItem;
- addItem: 'Inspect Class Hierarchy' action: #inspectClassHierarchy
- |
- inspectItem
- self evaluateForSelectedItem: [ :valueArray |
- (valueArray at: 1) inspect
- ]
- |
- inspectClassHierarchy
- parent inspectClassHierarchy
- ]
-
- Methods ObjectInspectorEditPane
- createPopUpMenu
- pMenu <- PopUpMenu new; owner: self; create.
- pMenu addItem: 'Accept' action: #changeValue;
- addItem: 'Cancel' action: #cancel.
- |
- showValue: aValue
- (aValue notNil) ifTrue: [
- self clearAllText; print: ((aValue at: 1) printString).
- pMenu enableItem: 1; enableItem: 2
- ]
- ifFalse: [
- pMenu disableItem: 1; disableItem: 2
- ]
- |
- changeValue: valueArray
- | s |
- (valueArray notNil) ifTrue: [
- inspectorTemp001 <- theObject.
- s <- 'inspectorTemp001 basicAt: ' ,
- (valueArray at: 2) printString ,
- ' put: ' , (self text).
- [
- (s execute) notNil ifTrue: [
- valueArray
- at: 1
- put: (inspectorTemp001 basicAt: (valueArray at: 2))
- ]
- ] fork
- ]
- ]
-
- Methods ObjectInspector 'all'
- createPanes
- listPane <- ObjectInspectorListPane new.
- editPane <- ObjectInspectorEditPane new.
- |
- makeTitle
- ^ 'Instance of: ' , ((theObject class) printString).
- |
- createListFrom: anObject
- | varNames t j a |
- nameList <- List new.
- j <- anObject basicSize.
- t <- anObject class.
- [t notNil] whileTrue: [
- varNames <- t variables.
- (varNames notNil) ifTrue: [
- varNames reverseDo: [:varName |
- a <- Array new: 2; at: 1 put: (anObject basicAt: j); at: 2 put: j.
- nameList addFirstLink: (Link new;
- value: a;
- key: (varName asString)).
- j <- j - 1
- ]
- ].
- nameList addFirstLink: (Link new; value: nil;
- key: ('=== ' , (t printString) , ' ===') ).
- t <- t superClass
- ].
- ^ nameList
- |
- inspectClassHierarchy
- (theObject class) inspect
- ]
-
- Methods CHInspectorEditPane
- createPopUpMenu
- pMenu <- PopUpMenu new; owner: self; create.
- pMenu addItem: 'Add Variables' action: #addVariables;
- addItem: 'Remove Variables' action: #removeVariables;
- addItem: 'Cancel' action: #cancel.
- |
- showValue: aClass
- | v |
- v <- aClass variables.
- self clearAllText.
- (v isNil) ifTrue: [
- self print: '<No instance variables>'.
- pMenu enableItem: 1; disableItem: 2; enableItem: 3
- ]
- ifFalse: [
- v do: [:c | self print: (c asString) , newLine ].
- pMenu enableItem: 1; enableItem: 2; enableItem: 3
- ].
- selectedClass <- aClass
- |
- addVariables | a |
- a <- (self text) words: [:x | x isAlphaNumeric ].
- a do: [ :x | selectedClass addInstanceVariable: (x asSymbol) ].
- self showValue: selectedClass
- |
- removeVariables | a r |
- a <- (self selectedText) words: [:x | x isAlphaNumeric ].
- r <- smalltalk inquire: 'Please confirm removal of ',
- (a size) asString, ' variables'.
- (r isNil) ifFalse: [
- r ifTrue: [
- a do: [ :x | selectedClass removeInstanceVariable: (x asSymbol) ]
- ]
- ].
- self showValue: selectedClass
- |
- changeValue: valueArray
- | s |
- (valueArray notNil) ifTrue: [
- inspectorTemp001 <- theObject.
- s <- 'inspectorTemp001 basicAt: ' ,
- (valueArray at: 2) printString ,
- ' put: ' , ((parent editPane) text).
- [
- (s execute) notNil ifTrue: [
- valueArray
- at: 1
- put: (inspectorTemp001 basicAt: (valueArray at: 2))
- ]
- ] fork
- ]
- ]
-
- Methods ClassHierarchyInspector 'all'
- createPanes
- listPane <- ObjectInspectorListPane new.
- editPane <- CHInspectorEditPane new.
- |
- overrideDefaultPaneSettings
- listPane button2Action: nil.
- |
- makeTitle
- ^ 'Class: ' , (theObject printString).
- |
- createListFrom: aClass
- | classList dots |
- classList <- List new.
- aClass upSuperclassChain: [:c |
- classList addFirstLink: (Link new;
- value: c;
- key: (c printString) )
- ].
- dots <- ''.
- classList newDo: [ :lk |
- lk key: (dots , (lk key)).
- dots <- (dots , '..')
- ].
- ^ classList
- ]
-
- Methods CollInspectorListPane
- createPopUpMenu
- pMenu <- PopUpMenu new; owner: self; create.
- pMenu addItem: 'Inspect' action: #inspectItem;
- addItem: 'Add Key' action: #addKey;
- addItem: 'Remove Key' action: #removeKey
- |
- addKey
- | ky |
- ky <- smalltalk getPrompt: 'Enter a key:'.
- (ky ~= '') ifTrue: [
- [
- (parent executeAnAt: ky withPut: 'nil') notNil
- ifTrue: [
- parent refreshListPane
- ]
- ] fork
- ]
- |
- removeKey
- | r |
- self withSelectedItemSend: #removeKey: to: self
- |
- removeKey: valueArray
- | r |
- (valueArray notNil) ifTrue: [
- r <- smalltalk inquire: ('Please confirm removal of item ',
- ((valueArray at: 2) asString) ).
- (r isNil) ifFalse: [
- r ifTrue: [
- (parent theObject) removeKey: (valueArray at: 2).
- parent refreshListPane.
- (parent editPane) cancel
- ]
- ]
- ]
- |
- inspectItem
- self evaluateForSelectedItem: [ :valueArray |
- (valueArray at: 1) inspect
- ]
- ]
-
- Methods CollInspectorEditPane
- createPopUpMenu
- pMenu <- PopUpMenu new; owner: self; create.
- pMenu addItem: 'Accept' action: #changeValue;
- addItem: 'Cancel' action: #cancel.
- |
- showValue: aValue
- aValue notNil ifTrue: [
- self clearAllText;
- print: ((aValue at:1) printString).
- pMenu enableItem: 1; enableItem: 2
- ]
- ifFalse: [
- pMenu disableItem: 1; disableItem: 2
- ]
- |
- changeValue: valueArray
- (valueArray notNil) ifTrue: [
- [
- (parent executeAnAt: ((valueArray at: 2) printString)
- withPut: ((parent editPane) text))
- notNil ifTrue: [
- parent refreshListPane
- ]
- ] fork
- ]
- ]
-
- Methods CollectionInspector 'all'
- createPanes
- listPane <- CollInspectorListPane new.
- editPane <- CollInspectorEditPane new.
- |
- makeTitle
- ^ 'Collection: ' , (theObject class printString).
- |
- createListFrom: aCollection
- | theList a l |
- theList <- List new.
- aCollection binaryDo: [:k :v |
- l <- Link new.
- a <- Array new: 3; at: 1 put: v; at: 2 put: k; at: 3 put: l.
- l value: a; key: ((k printString) , ' -> ' , (v printString)).
- theList addLastLink: l
- ].
- ^ theList
- |
- executeAnAt: atText withPut: putText
- | s |
- inspectorTemp001 <- theObject.
- s <- 'inspectorTemp001 at: ', atText, ' put: ', putText.
- ^ (s execute)
- |
- refreshListPane
- self refreshListPane: theObject
- ]
-
- Methods ArrayInspectorListPane 'all'
- addKey
- parent addKey
- |
- removeKey: valueArray
- (valueArray notNil) ifTrue: [
- r <- smalltalk inquire: ('Please confirm removal of item ',
- ((valueArray at: 2) asString) ).
- (r isNil) ifFalse: [
- r ifTrue: [
- (parent theObject) removeValues: [ :y | y = (valueArray at: 1) ].
- parent refreshListPane.
- (parent editPane) cancel
- ]
- ]
- ]
- ]
-
- Methods ArrayInspector 'all'
- createPanes
- listPane <- ArrayInspectorListPane new.
- editPane <- CollInspectorEditPane new.
- |
- makeTitle
- ^ 'Array: ' , (theObject class printString).
- |
- addKey
- theObject <- (theObject grow: nil).
- self refreshListPane: theObject
- ]